package com.sunther.document.controller;

import com.sunther.document.service.MsgService;
import com.sunther.idb.common.util.WebResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author csb
 * @description: TODO
 * @date 2023/6/27 10:45
 */
@RestController
@RequestMapping("/msg")
public class MsgController {

    @Autowired
    private MsgService msgService;

    @GetMapping("/list")
    public WebResult list(@RequestParam(required = false) String keyword,
                          @RequestParam(required = false) Integer state) {
        try {
            return WebResult.success("操作成功",msgService.listByKeyword(keyword,state));
        }catch (Exception e) {
            return WebResult.failure("操作失败");
        }
    }

    @GetMapping("/setRead")
    public WebResult setRead(HttpServletRequest request) {
        try {
            msgService.setRead(request);
            return WebResult.success("操作成功");
        }catch (Exception e) {
            return WebResult.failure("操作失败");
        }
    }

}
